package com.aiuren.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import com.aiuren.web.vo.FileBean;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings( { "serial", "static-access" })
public class UploadAction extends ActionSupport implements ModelDriven {

	FileBean fb = new FileBean();

//	public String filterType(String[] types) {
//		String fileType = fb.getUploadContentType();
//		for (String type : types) {
//			if (type.equals(fileType)) {
//				return null;
//			}
//		}
//		return INPUT;
//	}
//	
	public String execute() throws Exception {
		System.out.println("test---");
		FileOutputStream fos = new FileOutputStream(fb.getSavePath() + "\\"
				+ fb.getUploadFileName());
		FileInputStream fis = new FileInputStream(fb.getUpload());
		byte[] buffer = new byte[1024];
		int len = 0;
		while ((len = fis.read(buffer)) > 0) {
			fos.write(buffer, 0, len);
		}
		return SUCCESS;
	}

	public FileBean getModel() {
		return fb;
	}
}
